/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scm.rawMaterialPurchasing.session;

import commonInfrastructure.system.entity.SystemParameterEntity;
import commonInfrastructure.system.session.SystemSessionBean;
import java.io.IOException;
import java.util.Calendar;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.ejb.SessionContext;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;

/**
 *
 * @author ReinforceII
 */
@Stateless
@LocalBean
public class RawMaterialPurchasingTimerSessionBean {

    @EJB
    SystemSessionBean systemSessionBean;
    @EJB
    RawMaterialPurchasingSessionBean rawMaterialPurchasingSessionBean;
    @Resource
    private SessionContext ctx;
    SystemParameterEntity systemParameter;

    public void createTimer() {
        
        systemParameter = systemSessionBean.getSystemParameter();
        
        TimerService timerService = ctx.getTimerService();

        Timer rawMaterialRequirementTimer = timerService.createTimer(3000, systemParameter.getRawMaterialPurchasingTimer(), "This is raw material purchasing timer.");
    }
    
    @Timeout
    public void handleTimeout(Timer timer) throws IOException {
        if (timer.getInfo().toString().equals("This is raw material purchasing timer.")) {

            rawMaterialPurchasingSessionBean.generateWeeklyRawMaterialRequirementList(Calendar.getInstance().getTime());
            
        } else {
            System.out.println("********** Unknown Timer timedout: " + timer.getInfo().toString());
        }
    }
}
